package com.lottery.ruok.lottrey.adapter;

import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.lottery.ruok.lottrey.R;
import com.lottery.ruok.lottrey.bean.LiuheBean;
import com.lottery.ruok.lottrey.retrofitModule.response.GetLotteryDetailResponse;

import java.util.ArrayList;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by ASUS on 2017/11/13.
 */

public class LiuhecaiMainAdapter extends BaseAdapter {
    private ArrayList<LiuheBean> liuheBeens;
    private int type;
    private Context mContext;
    private GetLotteryDetailResponse getLotteryDetailResponse;

    public LiuhecaiMainAdapter(ArrayList<LiuheBean> a, int type, Context context, GetLotteryDetailResponse getLotteryDetailResponse) {//1是特码ab的特码a；2是特码ab的其它
        liuheBeens = a;
        this.type = type;
        mContext = context;
        this.getLotteryDetailResponse = getLotteryDetailResponse;
    }

    @Override
    public View getView(final int i, View view, ViewGroup viewGroup) {
        ViewHolder holder;
        if (view != null) {
            holder = (ViewHolder) view.getTag();
        } else {
            switch (type) {
                case 1:
                case 4:
                    view = LayoutInflater.from(mContext).inflate(R.layout.liuhe_item1, null);
                    break;
                case 2:
                    view = LayoutInflater.from(mContext).inflate(R.layout.liuhe_item2, null);
                    break;
                case 3:
                    view = LayoutInflater.from(mContext).inflate(R.layout.liuhe_item4, null);
                    break;
                case 5:
                    view = LayoutInflater.from(mContext).inflate(R.layout.liuhe_item6, null);
                    break;
                case 6:
                    view = LayoutInflater.from(mContext).inflate(R.layout.liuhe_item7, null);
                    break;
            }
            holder = new ViewHolder(view);
            switch (type) {
                case 3:
                    holder.nums = view.findViewById(R.id.nums);
                    holder.zodiac = view.findViewById(R.id.zodiac);
                    break;
                case 6:
                    holder.nums = view.findViewById(R.id.nums);
                    break;
                case 1:
                case 4:
                    holder.shengxiao = view.findViewById(R.id.shengxiao);
                    break;
            }
            view.setTag(holder);
        }

        holder.odds.setText(liuheBeens.get(i).odd);
        holder.number.setText(liuheBeens.get(i).number);
        if (type == 4) {
            holder.odds.setVisibility(View.GONE);
        }

        switch (type) {
            case 1:
            case 4:
                if (liuheBeens.get(i).choose) {
                    if (getLotteryDetailResponse.getColor().getRed().indexOf(liuheBeens.get(i).number) != -1) {
                        holder.number.setBackgroundResource(R.mipmap.reds);
                    } else if (getLotteryDetailResponse.getColor().getBlue().indexOf(liuheBeens.get(i).number) != -1) {
                        holder.number.setBackgroundResource(R.mipmap.blues);
                    } else if (getLotteryDetailResponse.getColor().getGreen().indexOf(liuheBeens.get(i).number) != -1) {
                        holder.number.setBackgroundResource(R.mipmap.greens);
                    }
                    holder.number.setTextColor(mContext.getResources().getColor(R.color.white));
                    holder.number.setTextSize(19);
                } else {
                    if (getLotteryDetailResponse.getColor().getRed().indexOf(liuheBeens.get(i).number) != -1) {
                        holder.number.setBackgroundResource(R.mipmap.red_big_gray);
                    } else if (getLotteryDetailResponse.getColor().getBlue().indexOf(liuheBeens.get(i).number) != -1) {
                        holder.number.setBackgroundResource(R.mipmap.blue_big_gray);
                    } else if (getLotteryDetailResponse.getColor().getGreen().indexOf(liuheBeens.get(i).number) != -1) {
                        holder.number.setBackgroundResource(R.mipmap.green_big_gray);
                    }
                    holder.number.setTextColor(mContext.getResources().getColor(R.color.lottery_black));
                    holder.number.setTextSize(14);
                }
                holder.shengxiao.setText(getLotteryDetailResponse.getSx().get(liuheBeens.get(i).number));
                break;
            case 2:
                if (liuheBeens.get(i).choose) {
                    view.setBackgroundResource(R.drawable.bg_corners_13);

                    holder.number.setTextColor(mContext.getResources().getColor(R.color.purples));
                    holder.odds.setTextColor(mContext.getResources().getColor(R.color.purples));
                } else {
                    view.setBackgroundResource(R.drawable.bg_corners_12);

                    holder.number.setTextColor(mContext.getResources().getColor(R.color.lottery_black));
                    holder.odds.setTextColor(Color.parseColor("#ff6c2c"));
                }
                break;
            case 3:
                if (liuheBeens.get(i).choose) {
                    view.setBackgroundResource(R.mipmap.card);

                    holder.odds.setTextColor(mContext.getResources().getColor(R.color.lottery_black));
                    holder.nums.setTextColor(mContext.getResources().getColor(R.color.purples));
                } else {
                    view.setBackgroundResource(R.mipmap.cardno);

                    holder.odds.setTextColor(Color.parseColor("#ff6c2c"));
                    holder.nums.setTextColor(mContext.getResources().getColor(R.color.lottery_black));
                }

                if (liuheBeens.get(i).nums == null) {
                    holder.nums.setVisibility(View.INVISIBLE);
                } else {
                    holder.nums.setVisibility(View.VISIBLE);
                    holder.nums.setText(liuheBeens.get(i).nums);
                }
                if (liuheBeens.get(i).odd == null) {
                    holder.odds.setVisibility(View.INVISIBLE);
                } else {
                    holder.odds.setVisibility(View.VISIBLE);
                    holder.odds.setText("赔率:" + liuheBeens.get(i).odd);
                }
                if (liuheBeens.get(i).color != 0) {
                    holder.number.setTextColor(liuheBeens.get(i).color);
                }

                if (liuheBeens.get(i).number != null) {
                    switch (liuheBeens.get(i).number) {
                        case "鼠":
                            holder.zodiac.setImageResource(R.mipmap.mouse);
                            holder.zodiac.setVisibility(View.VISIBLE);
                            break;
                        case "牛":
                            holder.zodiac.setImageResource(R.mipmap.cow);
                            holder.zodiac.setVisibility(View.VISIBLE);
                            break;
                        case "虎":
                            holder.zodiac.setImageResource(R.mipmap.tiger);
                            holder.zodiac.setVisibility(View.VISIBLE);
                            break;
                        case "兔":
                            holder.zodiac.setImageResource(R.mipmap.rabbit);
                            holder.zodiac.setVisibility(View.VISIBLE);
                            break;
                        case "龙":
                            holder.zodiac.setImageResource(R.mipmap.dragon);
                            holder.zodiac.setVisibility(View.VISIBLE);
                            break;
                        case "蛇":
                            holder.zodiac.setImageResource(R.mipmap.snake);
                            holder.zodiac.setVisibility(View.VISIBLE);
                            break;
                        case "马":
                            holder.zodiac.setImageResource(R.mipmap.horse);
                            holder.zodiac.setVisibility(View.VISIBLE);
                            break;
                        case "羊":
                            holder.zodiac.setImageResource(R.mipmap.sheep);
                            holder.zodiac.setVisibility(View.VISIBLE);
                            break;
                        case "猴":
                            holder.zodiac.setImageResource(R.mipmap.monkey);
                            holder.zodiac.setVisibility(View.VISIBLE);
                            break;
                        case "鸡":
                            holder.zodiac.setImageResource(R.mipmap.chicken);
                            holder.zodiac.setVisibility(View.VISIBLE);
                            break;
                        case "狗":
                            holder.zodiac.setImageResource(R.mipmap.dog);
                            holder.zodiac.setVisibility(View.VISIBLE);
                            break;
                        case "猪":
                            holder.zodiac.setImageResource(R.mipmap.pig);
                            holder.zodiac.setVisibility(View.VISIBLE);
                            break;
                        default:
                            holder.zodiac.setVisibility(View.GONE);
                            break;
                    }
                } else {
                    holder.zodiac.setVisibility(View.GONE);
                }
                break;
            case 5:
                if (liuheBeens.get(i).odd == null) {
                    holder.odds.setVisibility(View.INVISIBLE);
                } else {
                    holder.odds.setVisibility(View.VISIBLE);
                    holder.odds.setText("赔率:" + liuheBeens.get(i).odd);
                }

                if (liuheBeens.get(i).choose) {
                    view.setBackgroundResource(R.mipmap.card);

                    holder.odds.setTextColor(mContext.getResources().getColor(R.color.lottery_black));
                    holder.number.setTextColor(mContext.getResources().getColor(R.color.purples));
                } else {
                    view.setBackgroundResource(R.mipmap.cardno);

                    holder.odds.setTextColor(Color.parseColor("#ff6c2c"));

                    if (liuheBeens.get(i).color != 0) {
                        holder.number.setTextColor(liuheBeens.get(i).color);
                    } else {
                        holder.number.setTextColor(mContext.getResources().getColor(R.color.lottery_black));
                    }
                }
                break;
            case 6:
                if (liuheBeens.get(i).choose) {
                    view.setBackgroundResource(R.mipmap.card);

                    holder.odds.setTextColor(mContext.getResources().getColor(R.color.lottery_black));
                    holder.nums.setTextColor(mContext.getResources().getColor(R.color.purples));
                    holder.number.setTextColor(mContext.getResources().getColor(R.color.purples));
                } else {
                    view.setBackgroundResource(R.mipmap.cardno);

                    holder.odds.setTextColor(Color.parseColor("#ff6c2c"));
                    holder.nums.setTextColor(mContext.getResources().getColor(R.color.lottery_black));
                    holder.number.setTextColor(mContext.getResources().getColor(R.color.lottery_black));
                }

                if (liuheBeens.get(i).nums == null) {
                    holder.nums.setVisibility(View.INVISIBLE);
                } else {
                    holder.nums.setVisibility(View.VISIBLE);
                    holder.nums.setText(liuheBeens.get(i).nums);
                }
                if (liuheBeens.get(i).odd == null) {
                    holder.odds.setVisibility(View.INVISIBLE);
                } else {
                    holder.odds.setVisibility(View.VISIBLE);
                    holder.odds.setText("赔率:" + liuheBeens.get(i).odd);
                }
                break;
        }

        return view;
    }

    @Override
    public long getItemId(int i) {
        return 0;
    }

    @Override
    public Object getItem(int i) {
        return null;
    }

    @Override
    public int getCount() {
        return liuheBeens.size();
    }

    static class ViewHolder {
        @BindView(R.id.number)
        TextView number;
        @BindView(R.id.odds)
        TextView odds;

        TextView nums;//二连肖里的数字：例如 10 22 34 46
        ImageView zodiac;
        TextView shengxiao;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
